/*
 * @Description: 
 * @Author: zoe
 * @Date: 2024-10-08 09:13:46
 * @LastEditors: rendc
 * @LastEditTime: 2024-10-08 09:15:06
 */
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Test_List {
    public static void main(String[] args) {
        List<Integer> list1 = new ArrayList<>();
        list1.add(1);
        list1.add(2);
        list1.add(3);
        list1.add(4);
        list1.add(5);

        List<Integer> list2 = new ArrayList<>();
        list2.add(4);
        list2.add(5);
        list2.add(6);

        // 计算交集
        Set<Integer> intersection = new HashSet<>(list1);
        intersection.retainAll(new HashSet<>(list2));
        System.out.println("交集: " + intersection);

        // 计算差集
        Set<Integer> difference = new HashSet<>(list1);
        difference.removeAll(new HashSet<>(list2));
        System.out.println("差集: " + difference);
    }
}
